// pages/worker/worker.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    btmType: 1, //底部tag选项值
    btmNavs: [{
      id: 1,
      name: '产业工人'
    }, 
    // {
    //   id: 2,
    //   name: '建材家居'
    // }, 
    // {
    //   id: 3,
    //   name: '辅材品牌'
    // }
  ],
    workerList: [],
    building: [],
    material: [],
  },

  getList() {
    let that = this
    wx.$https('category.list', {
      type: 1,
    }).then(res => {
      that.setData({
        workerList: res
      })
    })
    wx.$https('category.list', {
      type: 2,
    }).then(res => {
      that.setData({
        building: res
      })
    })
    wx.$https('category.list', {
      type: 3,
    }).then(res => {
      that.setData({
        material: res
      })
    })
  },

  changeType: function (e) {
    let that = this;
    let type = e.currentTarget.dataset.type
    that.setData({
      btmType: type
    })
    this.setTitle()
  },

  setTitle() {
    let type = this.data.btmType
    let title = this.data.btmNavs.filter((item, index) => {
      return item.id == type
    })
    wx.setNavigationBarTitle({
      title: title[0].name,
    })
  },

  navWork(e) {
    let id = e.currentTarget.dataset.id
    wx.$nav('/pages/workerList/workerList', {
      id: id
    })
  },

  navShop(e) {
    let id = e.currentTarget.dataset.id
    wx.$nav('/pages/bathroom/bathroom', {
      id: id
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      btmType: options.type
    })
    this.setTitle()
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})